package com.csxy.hql.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.csxy.hql.entity.EduCourse;
import com.csxy.hql.entity.vo.CoursePublishVo;
import com.csxy.hql.entity.vo.CourseWebVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EduCourseMapper extends BaseMapper<EduCourse> {

    /**
     * 查询发布课程信息（替代 XML 中的 getPublishCourseInfo）
     */
    @Select({
            "SELECT",
            "ec.id,",
            "ec.title,",
            "ec.cover,",
            "ec.lesson_num AS lessonNum,",
            "ec.price,",
            "s1.title AS subjectLevelOne,",
            "s2.title AS subjectLevelTwo,",
            "t.name AS teacherName",
            "FROM edu_course ec",
            "LEFT JOIN edu_teacher t ON ec.teacher_id = t.id",
            "LEFT JOIN edu_subject s1 ON ec.subject_parent_id = s1.id",
            "LEFT JOIN edu_subject s2 ON ec.subject_id = s2.id",
            "WHERE ec.id = #{id}"
    })
    CoursePublishVo getPublishCourseInfo(String id);


    /**
     * 查询课程基础信息（替代 XML 中的 getBaseCourseInfo）
     */
    @Select({
            "SELECT",
            "ec.id,",
            "ec.title,",
            "ec.cover,",
            "ec.lesson_num AS lessonNum,",
            "ec.price,",
            "ec.buy_count as buyCount,",
            "ec.view_count as viewCount,",
            "esd.description,",
            "s1.title AS subjectLevelOne,",
            "s1.id as subjectLevelOneId,",
            "s2.id as subjectLevelTwoId,",
            "s2.title AS subjectLevelTwo,",
            "t.name AS teacherName,",
            "t.id as teacherId,",
            "t.avatar,",
            "t.intro",
            "FROM edu_course ec",
            "LEFT JOIN edu_teacher t ON ec.teacher_id = t.id",
            "LEFT JOIN edu_subject s1 ON ec.subject_parent_id = s1.id",
            "LEFT JOIN edu_subject s2 ON ec.id = s2.id",
            "LEFT JOIN edu_course_description esd ON ec.id = esd.id",
            "WHERE ec.id = #{id}"
    })

    CourseWebVo getBaseCourseInfo(String courseId);
}